import QtQuick 2.0
import QtQuick.Controls 2.5
import QtQuick.Dialogs 1.2
import FileHandler 1.0
import TransferSocket 1.0

Rectangle {
    id:com
    anchors.fill: parent
    Component.onCompleted: {
        console.log('===============fil')
    }

    property int unit: com.width / 16
    property var fileurl: ""
    Label{
        x:unit-50
        y:unit-50
        text: "文件传输"
        font.pointSize: 13
    }
    Rectangle {
        width: unit * 4.5
        height: unit * 4.5
        x: unit
        y: unit
        border.color: "black"
        Image {

            anchors.centerIn: parent
            source: "../images/add.png"
        }
        MouseArea {
            id:file_btn
            anchors.fill: parent
            enabled: true
            hoverEnabled: true

            property Component fileDialogPage;


            function finishCreation() {
                if (fileDialogPage.status === Component.Ready)
                {
                    console.log("Async Create Component Ready")
                    fileDialogPage_loader.sourceComponent = fileDialogPage;
                }
            }

            onClicked: {
                cursorShape = Qt.WaitCursor
                fileDialogPage = Qt.createComponent("FileDialogPage.qml", Component.Asynchronous);
                if (fileDialogPage.status === Component.Ready) {
                    finishCreation();
                } else {
                    console.log("Async Create Component Not Ready")
                    fileDialogPage.statusChanged.connect(finishCreation);
                }
            }
        }

        Loader {
            id: fileDialogPage_loader

            onSourceComponentChanged: {
                file_btn.cursorShape = Qt.ArrowCursor
            }

            Connections {
                target: FileHandler
                function onFileDialogPageCancle() {
                    fileDialogPage_loader.sourceComponent.destroy()
                }
            }
        }
    }
    Rectangle{
        width: unit*9
        height: unit*2
        x:unit*6
        y:unit
        border.color: "black"
        ListDevice{

        }
    }
    //刷新按钮
    Rectangle{
        width: unit*1.5
        height: unit*0.8
        y:3.2*unit
        x:6*unit
        border.color: "black"
        Button{
            anchors.centerIn: parent
            width: parent.width
            height: parent.height
            text: "刷新"
//            onClicked: {
//            }
        }
    }

    //发送按钮
    Rectangle{
        width:unit*1.5
        height: unit*0.8
        y:3.2*unit
        x:13.5*unit
        border.color: "black"
        Button{
            anchors.centerIn: parent
            width: parent.width
            height: parent.height
            text: "发送"
            onClicked: {
                //将url传回后台
                FileHandler.sendFile(fileDialog.fileUrl)
            }
        }
    }

    Rectangle{
        width: unit*9
        height: unit
        x:unit*6
        y:unit*4.5
//        border.color: "black"
        FileSave{

        }
    }
    Rectangle{
        width: unit*14
        height: unit*4
        x:unit*1
        y:unit*6.5
//        border.color: "black"
            FileTransfer{

            }
    }
}
